<template>
	<view>

		<view class="top-wrap">

			<text class="money-all">{{balance || '0.00'}}</text>
			<text style="font-size: 28upx;color: #A7A7A7;margin-top: 10upx;">累计收益(元)</text>

			<view class="withdraw-wrap">
				<text style="font-size: 28upx;color: #333333;margin-left: 30upx;">可提现金额：￥{{totalIncome || '0.00'}}</text>

				<text class="btn-detail" style="margin-right: 30upx;" @click="gowithdraw">提现</text>
			</view>
		</view>

		<view class="wrap">
			<view style="background-color: #FFFFFF; position: sticky; top: 0;z-index: 2;">

				<u-tabs-swiper :list="tabs" ref="tabs" :current="current" keyName="name" :is-scroll="false"
					@change="change" activeColor="#20C3AA" inactiveColor="#606266" bold="false">
				</u-tabs-swiper>

			</view>

			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom(0)">
						<view v-if="inList.length > 0" style="margin-top: 2upx;">

							<view v-for="(item, index) in inList" :key="index" @click="itemClick(item)">

								<view class="income_list">
									<image src="../../../static/mine/message/wz_icon.png" mode="scaleToFill" v-if="false"></image>

									<view class="income-item">
										<view class="income-title">
											<text class="income-title-name">{{filterNull(item.buyersVxName)}}</text>
											<text class="income-title-level">{{item.fsInfo}}</text>
										</view>

										<text class="income-time">{{filterNull(item.tradingHours)}}</text>
									</view>

									<text class="income-money">￥{{filterNull(item.earningsAmount)}}</text>

								</view>

								<u-line color="#efefef"></u-line>
							</view>

							<u-loadmore :status="loadStatus[0]" @loadmore="reachBottom(0)"></u-loadmore>
						</view>

						<no-data v-if="inList.length === 0"></no-data>

					</scroll-view>
				</swiper-item>

				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom(1)">
						<view v-if="outList.length > 0" style="margin-top: 2upx;">

							<view v-for="(item, index) in outList" :key="index" @click="itemClick(item)">

								<view class="income_list">
									<image src="../../../static/mine/message/wz_icon.png" mode="scaleToFill" v-if="false"></image>

									<view class="income-item">
										<view class="income-title">
											<text class="income-title-name" v-if="item.tradingChannel == 1" >微信</text>
											<text class="income-title-name" v-if="item.tradingChannel == 2">支付宝</text>
											<text class="income-title-name" v-if="item.tradingChannel == 3">线下转账</text>
											<text class="income-title-name" v-if="item.tradingChannel == 4">人工付款</text>
											<!-- <text class="income-title-level">{{item.commissionLevelStr}}</text> -->
										</view>

										<text class="income-time">{{filterNull(item.applyTime)}}</text>
									</view>

									<text class="income-money">￥{{filterNull(item.applyAmount)}}</text>

								</view>

								<u-line color="#efefef"></u-line>
							</view>

							<u-loadmore :status="loadStatus[1]" @loadmore="reachBottom(1)"></u-loadmore>
						</view>

						<no-data v-if="outList.length === 0"></no-data>

					</scroll-view>
				</swiper-item>

			</swiper>



		</view>





	</view>
</template>

<script>
	import {
		memberAccount,
		apiReturnsDetailedList,
		withdrawalRecord
	} from '../../../common/api.js';
	export default {
		data() {
			return {
				tabs: [{
						name: '收益明细'
					},
					{
						name: '使用明细'
					}
				],
				balance : '',
				totalIncome : '',
				current: 0,
				swiperCurrent: 0,
				inList: [],
				outList: [],
				dx: 0,
				inLoadStatus: 'loadmore',
				outLoadStatus :  'loadmore',
				inPageNo: 1,
				outPageNo: 1,
				pageNo: 1,
				pageSize: 10,
			}
		},
		onLoad() {
			this.getData();
			this.getReturnsDetailedList();
			this.getWithdrawalRecord();
		},
		methods: {
			
			getData() {
				//获取累积收益及提现金额
				memberAccount(
				  this.$store.state.user.userInfo.customerId
				).then(res=> {
					this.balance = res.balance;
					this.totalIncome = res.totalIncome;
				})
			},
			
			//客户收益明细
		  getReturnsDetailedList() {
				apiReturnsDetailedList({
					memberNo : this.$store.state.user.userInfo.customerId,
					pageNo : this.inPageNo,
					pageSize : this.pageSize
				}).then(res => {
					
					if (this.inPageNo == 1) {
						this.inList = [];
						this.inPageNo++;
					
						this.inLoadStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.inPageNo++;
					
							this.inLoadStatus = 'loadmore';
						} else {
					
							this.inLoadStatus = 'nomore';
						}
					}
					
					if (!uni.$u.test.isEmpty(res)) {
						this.inList = this.inList.concat(res);
					}
					
					
					
				}) 
			},
			//提现记录
			getWithdrawalRecord() {
				withdrawalRecord({
					memberNo : this.$store.state.user.userInfo.customerId,
					pageNo : this.outPageNo,
					pageSize : this.pageSize
				}).then(res=> {
					if (this.outPageNo == 1) {
						this.outList = [];
						this.outPageNo++;
					
						this.outLoadStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.outPageNo++;
					
							this.outLoadStatus = 'loadmore';
						} else {
					
							this.outLoadStatus = 'nomore';
						}
					}
					
					if (!uni.$u.test.isEmpty(res)) {
						this.outList = this.outList.concat(res);
					}
				})
			},
			
			// tab栏切换
			change(index) {
				this.swiperCurrent = index;
			},

			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},

			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			
			gowithdraw(){
				uni.navigateTo({
					url:'../withdraw/withdraw'
				})
			},

			reachBottom(type) {
        this.inLoadStatus = 'loading';
				this.outLoadStatus = 'loading';
				switch (type) {
					case 0:
						this.pageNo = this.inPageNo;
						this.type = '1';
						this.getReturnsDetailedList();
						break;
					case 1:
						this.pageNo = this.outPageNo;
						this.type = '2';
						this.getWithdrawalRecord();
						break;
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.top-wrap {
		@include flex(column);
		align-items: center;
		height: 256upx;
		background-color: $white;

		.money-all {
			font-size: 45upx;
			font-weight: bold;
			color: $green12;
			margin-top: 30upx;
		}

		.withdraw-wrap {
			width: 100%;
			@include flex;
			justify-content: space-between;
			margin: 20upx 0 0;
			align-items: center;

		}
	}

	.wrap {
		margin-top: 20upx;
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top) - 276upx);
		width: 100%;
	}

	.swiper-box {
		flex-grow: 1;
	}

	.swiper-item {
		height: 100%;
	}

	.income_list {
		@include flex;
		width: 100%;
		height: 130upx;
		align-items: center;
		background-color: $white;

		image {
			width: 60upx;
			height: 60upx;
			margin-left: 40upx;
		}

		.income-item {
			flex-grow: 1;
			margin-left: 40upx;
			@include flex(column);

			.income-title {
				@include flex;
				align-items: center;

				.income-title-name {
					font-size: 28upx;
					color: $black33;
					margin-right: 10upx;
				}

				.income-title-level {
					font-size: 24upx;
					color: $white;
					line-height: 45upx;
					text-align: center;
					padding: 0 18upx;
					border-radius: 90upx;
					background-color: $green12;
				}

			}

			.income-time {
				font-size: 26upx;
				color: $graya7;
				margin-top: 10upx;
			}
		}

		.income-money {
			color: $green12;
			font-weight: bold;
			font-size: 28upx;
			margin-right: 40upx;
		}

	}
</style>
